/* Controls the post processing of a field when the focus moves away from
   the field. This means validy checking, after change events and updating
   calculate fields. */

var NextTimeDontCheck = false;

// handle post processing for the fields. That is when focus
// moves away from the field
function doPostProcess(e) {
    fieldName = e.target.name;
    fieldTag =extractTag(fieldName);

    /* If value in the field has not changed no checks needed. Only
       when there was an illegal value in the field go on and check it.*/
    if (((LastFocused == fieldName) &&
        (OrginalValue == e.target.value) &&
        (ErrorField != fieldName)) ||
        (NextTimeDontCheck)) {
            NextTimeDontCheck = false;
            return;
    }

    ErrorField = "";

    /* Perform type checking */
    if (!typeCheck(e)) {
        ErrorField = fieldName;
        alert(dzLabel_failed_type_check);
        setTimeout('document.NalleForm.'+fieldName+'.focus()', 10);
        return;
    };

    /* Has this field influence on fetch fields? */
    if (eval('typeof(dzFetch_'+fieldTag+')') != 'undefined') {
            submitNalle("nalle", fieldName, 'EFetch', "");
    }

    /* Does field need validation? */
    if (eval('typeof(dzValidate_'+fieldTag+')') != 'undefined') {
        /* If validation fails return focus here */
        if (!validateField(fieldName, e.target.value)) {
           ErrorField = fieldName;
           setTimeout('document.NalleForm.'+fieldName+'.focus()', 10);
           return;
        };
    }

    /* Is after change needed? */
    if (eval('typeof(dzAC_'+fieldTag+')') != 'undefined') {
        handleAfterChange(fieldName);
    }
    /* Is there any calculate fields that must be updated? */
    /* Check that the field that caused this event has dependecies */
    if (eval('typeof(dzDep_'+fieldTag+')') != 'undefined') {
        handleCalculateField(fieldName, true);
    }
//    if (FilterEventSources != "") {
//        src_arr = FilterEventSources.split(',');
//        if (findArray(grp, src_arr) >= 0) {
//            submitNalle("nalle", fieldName, 'EFilterChange', "");
//        }
//    }

    return false;
} // doPostProcess()
